package com.org.redis.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class Redis {

    @Value("redis.host")
    private String host;
    @Value("redis.port")
    private int port;
    @Value("redis.database")
    private int database;
    @Value("redis.read.host")
    private String readHost;
    @Value("redis.read.port")
    private int readPort;
    @Value("redis.read.database")
    private int readDatabase;

    @PostConstruct
    public void init() {
        RedisConfig.setConfig(this);
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public int getDatabase() {
        return database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public String getReadHost() {
        return readHost;
    }

    public void setReadHost(String readHost) {
        this.readHost = readHost;
    }

    public int getReadPort() {
        return readPort;
    }

    public void setReadPort(int readPort) {
        this.readPort = readPort;
    }

    public int getReadDatabase() {
        return readDatabase;
    }

    public void setReadDatabase(int readDatabase) {
        this.readDatabase = readDatabase;
    }

    @Override
    public String toString() {
        return "Redis{" +
                "host='" + host + '\'' +
                ", port=" + port +
                ", database=" + database +
                ", readHost='" + readHost + '\'' +
                ", readPort=" + readPort +
                ", readDatabase=" + readDatabase +
                '}';
    }
}
